<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Shop\Address;
use App\Models\Shop\Customer;

class AddressController extends Controller
{
    function index()
    {
        $addresses = Address::where('customer_id', session('customer.id'))->get();
        return view('home.address_list')->with('addresses', $addresses);
    }
    function store(Request $request)
    {
        return $request->all();
    }
    function create()
    {
        return view('home.new_address');
    }
    //设置用户的默认地址
    function default_address(Request $request)
    {
        Customer::where('id', session('customer.id'))->update(['address_id' => $request->address_id]);

        //重新设置session
        $customer = session()->get('customer');
        $customer['address_id'] = $request->address_id;
        session()->put('customer', $customer);
    }
}
